home *** CD-ROM | disk | FTP | other *** search
- /*
- ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- File : DeviceTree.c
- Author : Ben Manuto
- Creation : Thursday, April 7, 1994 10:49:13 AM
- Copyright : Copyright © 1994, Apple Computer, Inc. All rights reserved.
-
- Purpose : To Display the Expansion Manager Device Tree.
-
- Revisions :
- ---------------------------------------------------------------------------------
- Date | Who | What
- ---------------------------------------------------------------------------------
- ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- */
-
-
- #include <stdio.h>
- #include <types.h>
- #include <Errors.h>
- #include <Memory.h>
- #include <String.h>
-
- #include "ExpansionBus.h"
- #include "DeviceTree.h"
-
- // •••••••••••••••••••••••••••••••••••••••••••••
-
- main(int argc,char *argv[])
- {
- #pragma unused (argc);
- #pragma unused (argv);
-
- printf("\nDisplaying Expainsion Mgr Device Tree__________________________________\n\n");
-
- DisplayTree();
-
- return 0;
- }
-
-
- // •••••••••••••••••••••••••••••••••••••••••••••
- // DisplayTree
-
- void DisplayTree(void)
- {
- DeviceNodeID rootNode;
- OSErr error;
- char *indentSpace;
-
- error = DeviceTreeRoot(&rootNode); // Get the root device.
- if (error) {
- printf("Error getting root node. err = %d\n", error);
- return;
- }
-
- indentSpace = NewPtrClear(kMaxTreeLevel * 3); // We only want enough space for indenting kMaxTreeLevels.
- ScanDeviceTree(rootNode, rootNode, indentSpace, 0);
-
- DisposPtr(indentSpace); // Clean up our indentation string.
- }
-
-
- // •••••••••••••••••••••••••••••••••••••••••••••
- // ScanDeviceTree
- //
- // Recursively scans the device tree and displays all devices and properties.
-
- void ScanDeviceTree(DeviceNodeID firstNode, // The first child node ina peer chain.
- DeviceNodeID nextNode, // The current node we're looking at
- char *indentSpace, // The spaces to indent our text.
- short treeLevel) // Number of child levels deep.
- {
- DeviceNodeInfo devInfo;
- OSErr error;
-
- error = DeviceTreeDeviceInfo(nextNode, &devInfo); // Get the device info
- if (error) {
- printf("•• Scan: DevInfo err = %d node = %lx\n",
- error, nextNode);
- return;
- }
-
- printf("\n%s•• Tree Level --> %d\n", indentSpace, treeLevel);
- error = DisplayDeviceAndProperties(nextNode, // Display the current device and properties.
- indentSpace);
-
- if (devInfo.childNode != 0L) { // This node isn't it, so are there any children?
- if (treeLevel < kMaxTreeLevel) // Add space for new level only if we're
- strcat(indentSpace, " "); // not more than kMaxTreeLevel levels deep
-
- ScanDeviceTree(devInfo.childNode, // Go down to the next child node.
- devInfo.childNode,
- indentSpace,
- treeLevel+1);
-
- indentSpace[(treeLevel*3)] = 0; // Take away spaces for popping out a level.
- }
-
- nextNode = devInfo.peerNode; // Set nextNode to the peerNode.
- if (nextNode != firstNode) // If ==, we have checked all peer nodes in the current peer chain.
- ScanDeviceTree(firstNode,
- nextNode,
- indentSpace,
- treeLevel);
- }
-
-
-
- // •••••••••••••••••••••••••••••••••••••••••••••
-
- OSErr DumpNode(DeviceNodeID theNode, char *indentSpace)
- {
- DeviceNodeInfo theInfo;
- OSErr error;
-
- error = DeviceTreeDeviceInfo(theNode, &theInfo);
- if (error) {
- printf("Could not display Device Tree Info. Error = %d", error);
- return error;
- }
-
- printf("%sNode name = '%s'\n", indentSpace, theInfo.name);
- printf("%sNode ID = $%08lx\n", indentSpace, theNode);
- printf("%sParent = $%08lx\n", indentSpace, theInfo.parentNode);
- printf("%sPeer = $%08lx\n", indentSpace, theInfo.peerNode);
- printf("%sChild = $%08lx\n", indentSpace, theInfo.childNode);
- printf("%sAttribute of this node = $%08x\n", indentSpace, theInfo.nodeAttributes);
-
- }
-
-
-
- // •••••••••••••••••••••••••••••••••••••••••••••
-
- OSErr DisplayDeviceAndProperties(DeviceNodeID deviceNode, char *indentSpace)
- {
- DeviceNodeInfo devInfo;
- DevicePropertyInfo propInfo;
- DevicePropertyID firstProp, currentProp;
- unsigned long i, propSize;
- char *propData;
- OSErr error;
-
- error = DeviceTreeDeviceInfo(deviceNode, &devInfo); // Get the device info.
- if (error) return error;
-
- DumpNode(deviceNode, indentSpace);
-
- firstProp = currentProp = devInfo.propertyNode; // Get the first property
-
- do {
- error = DeviceTreePropertyInfo(currentProp, &propInfo); // Get the property info.
- if (error) return error;
-
- printf("%s|\n",indentSpace);
- printf("%s| Property Name = '%s'\n",indentSpace, propInfo.name);
- printf("%s| Property node = $%08lx\n", indentSpace, devInfo.propertyNode);
- printf("%s| Peer Property = $%08lx\n", indentSpace, propInfo.peerNode);
- printf("%s| Property Size = %d (bytes)\n", indentSpace, propInfo.propertySize);
-
- if (propInfo.propertySize <= 512) // If Property <= 512
- propSize = propInfo.propertySize; // Go ahead and grab the whole thing.
- else
- propSize = 512; // else max out at 512 bytes.
-
- if (propInfo.propertySize <= 0)
- printf("%s| There is no data for this Property!\n", indentSpace);
- else {
- propData = NewPtr(propSize); // allocate space
- if (error = MemError()) {
- printf("•• Unable to Allocate space for Property Data. Err = %d\n\n", error);
- return error;
- }
-
- error = DeviceTreeGetProperty(currentProp,
- propData,
- propInfo.propertySize);
- if (error)
- printf("•• Could not Get Property Data. Error = %d", error);
- else {
- printf("%s| Property Data (Str) = '%s'\n", // Assumes null terminated string.
- indentSpace,
- propData);
-
- printf("%s| Property Data (Bytes) = [", indentSpace);
- for (i = 0; i < propSize; i++)
- printf("$%02hx ", propData[i]);
- printf("]\n");
- }
-
- DisposPtr(propData); // Get rid of property data.
- }
- currentProp = propInfo.peerNode;
- } while (firstProp != currentProp); // If first == current, we have seen all props.
-
- printf("%s|__________________________________________________\n", indentSpace);
-
- return noErr;
- }
-